
recode appHHSize13 (0/1 = 2) (11/23 = 10), gen(hhsize13) 
global x = "i.HEIGHT muslim i.feducat i.meducat i.hhsize13 phoneFound"
gen wt = wt_interv

gen migrant = stillAbroadS2==1
label var migrant "Currently abroad"

replace logpccons_nf_health = 0 if cons_nf_health==0
replace logpceduExp = 0 if eduExp==0 
ren logpccons logconspc
replace expLargeAsset = 0 if buyLargeAsset==0
replace incLargeAsset = 0 if sellLargeAsset==0
replace expResidence = 0 if buyResidenc==0
replace expRepairs = 0 if didRepairs==0

gen pcnetLargeAsset = (expLargeAsset - incLargeAsset + expResidence + expRepairs)/HHsize_cons 
gen logpcnetLargeAsset = asinh(pcnetLargeAsset)

qui summ loglandValue
replace loglandValue = r(mean) if hasLand==1 & mi(loglandValue) // about 7% missing: not correlated with treatment status
replace loglandValue = 0 if hasLand==0 & mi(loglandValue)

tokenize "buyLargeAsset logpcexpLargeAsset sellLargeAsset logpcincLargeAsset buyResidence logpcexpResidence didRepairs logpcexpRepairs"
local len = wordcount("`*'")
forval i = 1(2)`len'{
	local j = `i' +1
	replace ``j'' = 0 if ``i''==0
}

gen hasCrop = (ausInc + amanInc + boroInc) !=0
gen logCropFert = asinh(cropFert) if hasCrop==1
gen hasCropFert = cropFert>0 if hasCrop==1
gen hasCropWage = cropWageexp>0 if hasCrop==1
gen logCropEquip = asinh(cropEquip) if hasCrop==1
gen hasCropEquip = cropEquip>0 if hasCrop==1
gen hasLivestock = lstckInc !=0 | lstckValue!=0
gen logLSValue = asinh(lstckValue) if hasLivestock==1 & lstckValue>0
gen logLSEquip = asinh(lstckEquip) if hasLivestock==1
gen hasLSEquip = lstckEquip>0 if hasLivestock==1
gen hasLSWage = lstckWageexp>0 if hasLivestock==1 
gen hasBus = nfbus
gen logBusValue = asinh(nfbusValue) if hasBus==1 & nfbusValue>0
gen hasBusWage = nfbusWagesLmon>0 if hasBus==1
gen logBusCap = asinh(nfbusCapExpLyr) if hasBus==1
gen hasBusCap = logBusCap>0 if hasBus==1

gen splitHH = appFormNewHH==1
gen hasNewMem = numNewHHMem>0 & !mi(numNewHHMem)

qui summ femaleDecChild
replace femaleDecChild = r(mean) if mi(femaleDecChild) 
qui summ femaleOnlyDecChild 
replace femaleOnlyDecChild = r(mean) if mi(femaleOnlyDecChild) 

replace loghhInc_home = 0 if loghhInc_home<0

gen nothead13 = relation_hhh13!=1 if !mi(relation_hhh13)
gen single13 = married13 !=1 if !mi(married13)
gen headFather = appChild==1 & headMale==1 
label var headFather "Father is HH head"


gen migMalay = migrated==1 & fmigDestMalay==1
label var migMalay "Migrated to Malaysia"

replace reasonNoMigrate = . if migrated==1
replace reasonT1 = . if migrated==1

gen logtransfer_in = log(transfers_in+1)
gen logtransfer_out = log(transfers_out+1)
gen trans_govngo = transfer_ngo>0 | transfer_gov>0 
gen trans_out = transfers_out >0 
gen trans_in = transfers_in>0

gen spouse_ed8 = spouse_educ>=8 & !mi(spouse_educ)
gen spouse_incHigh = spouse_incLmonth>=5000 & !mi(spouse_incLmonth)

recode eduYears (0/4 = 1 "Low") (5/7 = 2) (8/10=3) (12/17=4), gen(educat)
gen fHead13 = relation_hhh13 ==3 if !mi(relation_hhh13)

gen unmarried13 = married13==0
gen married = inlist(1, married13, marriedPost13)
label var married "Married"



global appBvars = "" 
************************
* Balance checks
************************
global balance "age height muslim literate eduYears fAlive fedu mAlive medu married13 appHHSize13 monthWork2012 monthInc2012"
label var age "Age" 
label var height "Height, inches"
label var fedu "Father's years of education"
label var medu "Mother's years of education"
label var married13 "Married before lottery"
label var appHHSize13 "HH size before lottery"
global fs "migrated g2gmig nong2gmig fdurMon tmigMon tmigMonG fmigDestMalay fmigDestGulf"


